﻿
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class redirector
    Inherits requestProcessor

    Public Const _pathidentity As String = "/redir"
    Public Const urlquery As String = "url"

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Public Overrides Function process(ByVal context As httpContext) As Boolean
        Dim url As String
        url = context.url.query(urlquery)

        If isemptystring(url) Then
            Dim page As xhtmlpage = Nothing
            page = New xhtmlpage(context.buff())
            page.title().text = applicationSign() + " - redirctor - input url"

            Dim form As form = Nothing
            form = New form(context.buff())
            form.action = strmid(_pathidentity, strlen(network.pathSeperator))
            page.body().addchild(form)

            Dim label As label = Nothing
            label = New label(context.buff())
            label.text = "please input link here."
            form.addchild(label)

            form.addchild(New br(context.buff()))

            Dim input As input = Nothing
            input = New input(context.buff())
            input.type = xhtmlctrl.input.type_enum.text
            input.name = urlquery
            form.addchild(input)

            form.addchild(New br(context.buff()))

            input = New input(context.buff())
            input.type = xhtmlctrl.input.type_enum.submit
            input.value = "submit"
            form.addchild(input)

            Return page.render()
        Else
            context.response().Redirect(url)
            Return True
        End If
    End Function
End Class
